<?php 
defined('IN_TS') or die('Access Denied.');

switch($ts){

	case "list":
		
		$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
		
		$url = SITE_URL.'index.php?app=task&ac=admin&mg=task&ts=list&page=';
		
		$lstart = $page*10-10;
		
		$arrTask = $new['task']->findAll('task',null,'addtime desc',null,$lstart.',10');
		
		$taskNum = $new['task']->findCount('task');
		
		$pageUrl = pagination($taskNum, 10, $page, $url);

		include template("admin/task_list");
		
		break;
		
	//审核
	case "isaudit":
		
		$taskid = intval($_GET['taskid']);
		
		$strTask = $new['task']->find('task',array(
			'taskid'=>$taskid,
		));
		
		if($strTask['isaudit'] == 0){
			
			$new['task']->update('task',array(
				'taskid'=>$taskid,
			),array(
				'isaudit'=>1,
			));
			
		}
		
		if($strTask['isaudit'] == 1){
			
			$new['task']->update('task',array(
				'taskid'=>$taskid,
			),array(
				'isaudit'=>0,
			));
			
		}
		
		qiMsg('操作成功');
		
		break;
	
	//推荐
	case "isrecommend":
		
		$taskid = intval($_GET['taskid']);
		
		$strTask = $new['task']->find('task',array(
			'taskid'=>$taskid,
		));
		
		if($strTask['isrecommend'] == 0){
			
			$new['task']->update('task',array(
				'taskid'=>$taskid,
			),array(
				'isrecommend'=>1,
			));
			
		}
		
		if($strTask['isrecommend'] == 1){
			
			$new['task']->update('task',array(
				'taskid'=>$taskid,
			),array(
				'isrecommend'=>0,
			));
			
		}
		
		qiMsg('操作成功');
		
		break;
		
	case "delete":
	
		$taskid = intval($_GET['taskid']);
		
		$strTask = $new['task']->find('task',array(
			'taskid'=>$taskid,
		));
		
		if($strTask['photo']){
			unlink('uploadfile/task/'.$strTask['photo']);
		}
		
		$new['task']->delete('task',array(
			'taskid'=>$taskid,
		));
		
		$new['task']->delete('task_comment',array(
			'taskid'=>$taskid,
		));
		
		$new['task']->delete('task_users',array(
			'taskid'=>$taskid,
		));
		
		qiMsg('删除成功');
	
		break;
		
}